<?php if (!defined('BASEPATH')) 	exit('No direct script access allowed'); ?>

<link href="<?php echo IMAGE_PATH(); ?>changeemail.css" rel="stylesheet" type="text/css">

<div id="am_xian" class="am_xian">

	<div class="fill">
		<div class="buzhou">
			<img src="<?php echo IMAGE_PATH(); ?>e_1.gif" alt="修改E-mail第一步">
			<script type="text/javascript">
				var p1 = "为了确保您的账户安全,请您输入网站的登录密码";
				var p2 = "请您输入新Email地址";
				var p3 = "请您确认新Email地址";
				var p4 = "请您输入下图中的字符";

				function focusCheck(dom, str) {
					if ($(dom).val().length > 0)
						$(dom).attr("class", "").next("p").attr("class", "").html("");
					else
						$(dom).attr("class", "").next("p").attr("class", "").html(str);
				}

				function CleanTxt(dom, str) {
					if ($(dom).val().length > 1) {
						$(dom).attr("class", "").next("p").html("").attr("class", "");
					}

				}

				var emailchecked = false;
				function IsUsedEmail(dom, email) {
					$.ajax({
						type : "POST",
						url : "/App_Services/wsMember.asmx/CheckUserByEmail",
						dataType : "text",
						contentType : "application/json;utf-8",
						data : "{email:'" + email.toLowerCase() + "'}",
						timeout : 10000,
						error : function(a, b, c) {
							emailchecked = true;
						},
						success : function(msg) {
							if (eval("(" + msg + ")")["d"]) {
								$(dom).attr("class", "red").next("p").html("Email地址已被占用，请使用其他Email地址").attr("class", "red");
								emailchecked = false;
							} else {
								$(dom).attr("class", "").next("p").html("恭喜！E-mail地址可用！").attr("class", "lv");
								emailchecked = true;
							}
						}
					});
					return emailchecked;
				}

				function regEmail(dom) {
					var email = $.trim($(dom).val());
					if (email.length > 0) {
						if (email == "colinyan@gmail.com") {
							$(dom).attr("class", "red").next("p").html("新Email地址不能与当前Email地址相同!").attr("class", "red");
							emailchecked = false;
						} else if (new RegExp("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*").test(email)) {
							if (new RegExp("^[A-Za-z-0-9._@]+$").test(email)) {
								IsUsedEmail(dom, email);
								if ($("#regEmailTxt").val().length > 0) {
									checkRegEmail("#regEmailTxt");
								}
							} else
								$(dom).attr("class", "red").next("p").html("只能由英文、数字、点、减号、下划线组成 !").attr("class", "red");
							emailchecked = false;
						} else {
							$(dom).attr("class", "red").next("p").html("Email地址格式错误,请重新输入!").attr("class", "red");
							emailchecked = false;
						}
					} else {
						$(dom).attr("class", "").next("p").html(p2).attr("class", "");
						emailchecked = false;
					}
				}

				var regEmailchecked = false;
				function checkRegEmail(dom) {
					var regEmail = $.trim($(dom).val());
					if (regEmail.length > 0) {
						if (regEmail == $("#newEmailTxt").val()) {
							regEmailchecked = true;
						} else {
							regEmailchecked = false;
							$(dom).attr("class", "red").next("p").html("重复输入地址与第一次不同，请重新输入！").attr("class", "red");
						}
					}
				}

				var checkcodechecked = false;
				function checkCode(dom) {
					var checkCode = $.trim($(dom).val()).toLowerCase();
					if (checkCode == "") {
						$(dom).nextAll("p").html("请您输入下图中的字符");
						checkcodechecked = false;
					} else {
						$.ajax({
							type : "GET",
							url : "/ValidateCode.ashx?s=regCode&code=" + checkCode + "&r=" + new Date(),
							dataType : "text",
							timeout : 10000,
							error : function(a, b, c) {
								checkcodechecked = true;
							},
							success : function(msg) {
								if (msg == '0') {
									checkcodechecked = false;
									$(dom).attr("class", "red").next("p").html("验证码错误，请重新输入!").attr("class", "red");
								} else {
									checkcodechecked = true;
									$(dom).attr("class", "").next("p").html("").attr("class", "");
								}
							}
						});
					}
				}

				function ClearnAll() {
					if (confirm("重新填写将清空表单,确定要重填吗?")) {
						$("#passwordTxt").val("").attr("class", "").next("p").attr("class", "").html(p1);
						$("#newEmailTxt").val("").attr("class", "").next("p").attr("class", "").html(p2);
						$("#regEmailTxt").val("").attr("class", "").next("p").attr("class", "").html(p3);
						$("#regCodeTxt").val("").attr("class", "").next("p").attr("class", "").html(p4);
						$("#regCheckCode").click();
					}
				}

				function CheckForm() {
					checkCode("#regCodeTxt");
					var flag = false;
					if ($.trim($("#passwordTxt").val()).length < 1) {
						$("#passwordTxt").attr("class", "red").next("p").html("请您输入网站密码").attr("class", "red");
						flag = false;
					}
					if ($.trim($("#newEmailTxt").val()).length < 1) {
						$("#newEmailTxt").attr("class", "red").next("p").html("请您输入新Email地址").attr("class", "red");
						flag = false;
					}
					if ($.trim($("#regEmailTxt").val()).length < 1) {
						$("#regEmailTxt").attr("class", "red").next("p").html("您重复输入新Email地址").attr("class", "red");
						flag = false;
					}
					if ($.trim($("#regCodeTxt").val()).length < 1) {
						$("#regCodeTxt").attr("class", "red").next("p").html("请您输入下图中的字符").attr("class", "red");
						flag = false;
					}
					if ($.trim($("#passwordTxt").val()).length > 0 && $.trim($("#newEmailTxt").val()).length > 0 && $.trim($("#regEmailTxt").val()).length > 0 && $.trim($("#regCodeTxt").val()).length > 0) {
						flag = true;
					}
					return flag;
				}

				function SubmitForm() {

					if (CheckForm()) {
						if (!checkcodechecked) {
							var checkCode = $.trim($("#regCodeTxt").val()).toLowerCase();
							if (checkCode == "") {
								$(dom).nextAll("p").html("输入下图中的字符！");
								checkcodechecked = false;
							} else {
								$.ajax({
									type : "GET",
									url : "/ValidateCode.ashx?s=regCode&code=" + checkCode + "&r=" + new Date(),
									dataType : "text",
									timeout : 10000,
									error : function(a, b, c) {
									},
									success : function(msg) {
										if (msg == '0') {
											$("#regCodeTxt").attr("class", "red").next("p").html("验证码错误，请重新输入！").attr("class", "red");
										} else {
											$("#regCodeTxt").attr("class", "").next("p").html("").attr("class", "");
											checkRegEmail("#newEmailTxt");
											if (emailchecked && regEmailchecked) {
												$("form")[0].submit();
											}
										}
									}
								});
							}
						} else {
							checkRegEmail("#newEmailTxt");
							if (emailchecked && regEmailchecked) {
								$("form")[0].submit();
							}
						}
					}
				}


				$(document).ready(function() {
					document.forms[0].action = window.location;
					$("#regCodeTxt").keydown(function(e) {
						if (e.keyCode == 13)
							SubmitForm();
					})
					regEmail("#newEmailTxt");
				});
			</script>
		</div>
		<div class="biao">
			<table>
				<tbody>
					<tr>
						<td class="z">当前E-mail地址：</td>
						<td>colinyan@gmail.com</td>
					</tr>
					<tr>
						<td class="z">输入网站密码：</td>
						<td>
						<input name="passwordTxt" id="passwordTxt" type="password" maxlength="20" onfocus="focusCheck(this,p1);checkCode(&#39;#regCodeTxt&#39;)" onkeyup="CleanTxt(this,p1)" onblur="checkCode(&#39;regCodeTxt&#39;);focusCheck(this,p1)" value="">
						<p style="">
							为了确保您的账户安全,请您输入网站的登录密码
						</p></td>
					</tr>
					<tr>
						<td class="z">新E-mail地址：</td>
						<td>
						<input name="newEmailTxt" id="newEmailTxt" maxlength="80" type="text" onfocus="focusCheck(this,p2);checkCode(&#39;#regCodeTxt&#39;)" onkeyup="CleanTxt(this,p2)" onblur="checkCode(&#39;regCodeTxt&#39;);focusCheck(this,p2);regEmail(this);" value="" class="">
						<p class="">
							请您输入新Email地址
						</p></td>
					</tr>
					<tr>
						<td class="z">重复输入新地址：</td>
						<td>
						<input name="regEmailTxt" id="regEmailTxt" maxlength="80" type="text" onfocus="focusCheck(this,p3);checkCode(&#39;#regCodeTxt&#39;)" onkeyup="CleanTxt(this,p3)" onblur="checkCode(&#39;regCodeTxt&#39;);focusCheck(this,p3);checkRegEmail(this);" value="">
						<p>
							请您确认新Email地址
						</p></td>
					</tr>
					<tr>
						<td class="z">验证码：</td>
						<td>
						<input name="regCodeTxt" id="regCodeTxt" maxlength="4" type="text" onfocus="focusCheck(this,p4)" onkeyup="CleanTxt(this,p4)" onblur="CleanTxt(this,p4);checkCode(this);focusCheck(this,p4)">
						<p id="checkCode">
							请您输入下图中的字符
						</p></td>
					</tr>
					<tr>
						<td class="z">&nbsp;</td>
						<td><span> 
							 <img id="regCheckCode" src="<?php echo CAPTCHA_IMG(); ?>" title="点击图片刷新" alt="验证码" 
                                  style="vertical-align:middle;cursor:pointer;width:131px;height:28px" 
                                  onclick="this.src=<?php echo CAPTCHA_IMG_RAN(); ?>"  border="0" > 
                            </span>
							<a style="cursor: pointer;" onclick="$(&quot;#regCheckCode&quot;).click();checkCode(&quot;#regCodeTxt&quot;)">看不清，换一张？</a></td>
					</tr>
				</tbody>
			</table>
		</div>
		<div class="tijiao">
			<input name="" type="button" value="确认修改" onmouseover="this.className=&#39;by&#39;" onmouseout="this.className=&#39;&#39;" onclick="SubmitForm()">
			<a style="cursor: pointer;" onclick="ClearnAll()">[重新填写]</a>
		</div>
	</div>

</div>
